package com.yunze.task.yunze.Automation;

import com.alibaba.fastjson.JSON;

import com.yunze.apiCommon.mapper.mysql.YzCardRouteMapper;
import com.yunze.apiCommon.utils.VeDate;
import com.yunze.common.config.MyDictionary;

import com.yunze.common.mapper.mysql.YzCardMapper;
import com.yunze.common.mapper.mysql.YzExecutionTaskMapper;
import com.yunze.common.mapper.mysql.automationCC.YzAutomationCcHisMapper;
import com.yunze.common.mapper.mysql.automationCC.YzAutomationCcMapper;
import com.yunze.common.mapper.mysql.automationCC.YzAutomationCcUrlMapper;
import com.yunze.common.mapper.mysql.card.YzApplicationforRenewalPrimaryMapper;
import com.yunze.common.mapper.mysql.card.YzCardDueSoonMapper;
import com.yunze.common.mapper.mysql.card.YzCardUsageReminderMapper;
import com.yunze.common.mapper.mysql.commodity.YzWxByProductAgentMapper;
import com.yunze.common.mapper.mysql.polling.YzCardPollingErrorGroupMapper;
import com.yunze.common.mapper.mysql.polling.YzCardPollingErrorMapper;
import com.yunze.common.mapper.mysql.polling.YzSynCardInfoMapper;
import com.yunze.common.utils.Email.EmailCc;
import com.yunze.common.utils.yunze.WriteCSV;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;
import java.util.*;

/**
 * 处理抄送失败邮件 [适配大部分]
 */
@Slf4j
@Component("emailRetry")
public class EmailRetry {


    @Resource
    private YzAutomationCcHisMapper yzAutomationCcHisMapper;
    @Resource
    private EmailCc emailCc;


    @Resource
    private YzWxByProductAgentMapper yzWxByProductAgentMapper;
    @Resource
    private YzCardDueSoonMapper yzCardDueSoonMapper;
    @Resource
    private YzExecutionTaskMapper yzExecutionTaskMapper;
    @Resource
    private YzAutomationCcMapper yzAutomationCcMapper;

    @Resource
    private YzAutomationCcUrlMapper yzAutomationCcUrlMapper;

    @Resource
    private WriteCSV writeCSV;


    @RabbitHandler
    @RabbitListener(queues = "admin_RetryCC_queue")
    public void ListenerRetryCC(String msg) {
        if (StringUtils.isEmpty(msg)) {
            return;
        }
        Map<String, Object> Pmap = JSON.parseObject(msg);
        Integer cc_count = Integer.parseInt(Pmap.get("cc_count").toString());
        String trigger_type = Pmap.get("trigger_type").toString();
//        RetryCC(cc_count,trigger_type);
        RESend(cc_count, trigger_type);
    }


    /**
     * 邮件抄送 重试
     *
     * @param cc_count 重试次数
     */
    public void RetryCC(Integer cc_count, String trigger_type) {
        Map<String, Object> findNotPerformed_Map = new HashMap<>();
        findNotPerformed_Map.put("trigger_type", trigger_type);
        findNotPerformed_Map.put("cc_count", cc_count);//重试次数
        List<Map<String, Object>> CcArr = yzAutomationCcHisMapper.findNotPerformed(findNotPerformed_Map);
        if (CcArr != null && CcArr.size() > 0) {
            //2.获取
            for (int i = 0; i < CcArr.size(); i++) {
                Map<String, Object> Cc_Map = CcArr.get(i);
                Map<String, Object> cc_parameter = JSON.parseObject(Cc_Map.get("cc_parameter").toString());
                String SendEmail = Cc_Map.get("cc_email").toString();
                Map<String, Object> updHisMap = new HashMap<>();
                updHisMap.put("id", Cc_Map.get("id"));
                Map<String, Object> Rmap = null;
                Boolean bool = false;
                String remark = "", cc_result = "0";
                try {
                    Rmap = SendCpu(trigger_type, cc_parameter, SendEmail);
                    bool = (Boolean) Rmap.get("bool");
                    if (bool) {
                        cc_result = "1";
                    }
                } catch (Exception e) {
                    remark = e.getMessage();
                    remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                }
                updHisMap.put("remark", remark);
                updHisMap.put("cc_result", cc_result);
                boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                log.info(">>自动化  [RetryCC] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
            }
        }
    }

    public Map<String, Object> SendCpu(String trigger_type, Map<String, Object> cc_parameter, String SendEmail) {
        Map<String, Object> Rmap = null;

        switch (trigger_type) {
            case "4":
                Rmap = emailCc.CardStatusAbnormal_default(cc_parameter, SendEmail);
                break;
            case "5":
                Rmap = emailCc.NotDividedIntoTariffGroups_default(cc_parameter, SendEmail);
                break;
            case "6":
                Rmap = emailCc.UndividedChannel_default(cc_parameter, SendEmail);
                break;
            case "7":
                Rmap = emailCc.CardConsumption_default(cc_parameter, SendEmail);
                break;
            case "8":
                Rmap = emailCc.usageMailReminder_default(cc_parameter, SendEmail);
                break;
            case "9":
                Rmap = emailCc.CardApiSynError_default(cc_parameter, SendEmail);
                break;
            case "10":
                Rmap = emailCc.CardApiSynError_default(cc_parameter, SendEmail);
                break;
            case "11":
                Rmap = emailCc.ApplicationForRenewal_default(cc_parameter, SendEmail);
                break;
            case "13":
                Rmap = emailCc.PerformTasks_default(cc_parameter, SendEmail, "系统通知");
                break;
            case "14":
                Rmap = emailCc.PerformTasks_default(cc_parameter, SendEmail, "系统通知");
                break;
            case "12":
                Rmap = emailCc.ServiceOperation(cc_parameter, SendEmail);//自动化 邮件抄送 重试[服务快到期运维]
                break;
            case "15":
                Rmap = emailCc.PerformTasks_default(cc_parameter, SendEmail, "系统预警");
                break;
        }
        return Rmap;
    }

    /**
     * RE:邮件重试抄送 2022年11月10日13:55:19
     */

    public void RESend(Integer cc_count, String trigger_type) {
        // 获取 重试 发送邮件的 类型 次数 以及 邮箱 id 等信息
        Map<String, Object> findNotPerformed_Map = new HashMap<>();
        findNotPerformed_Map.put("trigger_type", trigger_type);
        findNotPerformed_Map.put("cc_count", cc_count);//重试次数
        List<Map<String, Object>> CcArr = yzAutomationCcHisMapper.findNotPerformed(findNotPerformed_Map);

        Boolean bool = null;
        String remark = "", cc_result = "0";
        Map<String, Object> updHisMap = new HashMap<>();
        String SendEmail = null;
        //判断 查出来的CCArr不为空
        if (CcArr != null & CcArr.size() > 0) {

            try {
                //进行邮件抄送
                switch (trigger_type) { //根据 不同的任务类型进行 不同的邮件抄送

                    case "12":  //服务快到期发送      √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果
                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱

                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    emailServiceOperation();
                                    bool = true;
                                }catch(Exception e){
                                    bool = false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }
                        }
                        break;
                    case "4":  //服务快到期发送            √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果
                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱

                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    CCCardAbnormalStatus();
                                    bool = true;
                                }catch(Exception e){
                                    bool=false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                    case "5":  //自动化 邮件抄送 [未划分资费组]          √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果
                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱

                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    PayGroup();
                                    bool = true;
                                }catch(Exception e){
                                    bool = false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                    case "6":  //自动化 邮件抄送 [未划分通道]         √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果
                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱

                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    Passageway();
                                    bool = true;
                                }catch(Exception e){
                                    bool=false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                    case "7":  //轮询-卡状态                 √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果
                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱

                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    CardConsumption();
                                    bool = true;
                                }catch(Exception e){
                                    bool= false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                    case "8":  //自动化任务邮件抄送超百分比（80）               √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果
                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱

                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    Reminder("80");
                                    bool = true;
                                }catch(Exception e){
                                    bool = false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                    case "9":  //API同步错误-运营类型              √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果
                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱

                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    Aseot(trigger_type);
                                    bool = true;
                                }catch(Exception e){
                                    bool = false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                    case "10":  //API同步错误- 非运营类型               √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果

                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    Aseot(trigger_type);
                                    bool = true;
                                }catch(Exception e){
                                    bool = false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                    case "11":  //续费通知                      √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果

                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    CCExecution();
                                    bool = true;
                                }catch(Exception e){
                                    bool = false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                    case "13":  //续费通知                      √
                        //循环  将需要重试的任务 进行封装 : updHisMap ,当邮件成功发送时,去修改 任务的执行结果

                        for (int i = 0; i < CcArr.size(); i++) {
                            Map<String, Object> Cc_Map = CcArr.get(i);
                            SendEmail = Cc_Map.get("cc_email").toString(); //获取 需要抄送的邮箱
                            updHisMap.put("id", Cc_Map.get("id")); //任务id
                            if (SendEmail == null && SendEmail == "") {  // 如果没有配置邮箱 则直接结束
                                continue;
                            }else{
                                try{
                                    SynUpstreamCardNumberAdd();
                                    bool = true;
                                }catch(Exception e){
                                    bool = false;
                                }
                                if (bool != null && bool) {//是否进行 对 bool进行复制 或者 bool 是否为 true
                                    //当bool 为true 时,说明 邮件发送成功 则 进行 yz_automation_cc_his 表的 cc_result字段进行修改 ,修改为 1 即成功状态
                                    cc_result = "1";
                                    updHisMap.put("remark", remark);
                                    updHisMap.put("cc_result", cc_result);
                                    boolean updHis = yzAutomationCcHisMapper.updCcCount(updHisMap) > 0;
                                    log.info(">>自动化  [RESend] - trigger_type [{}] 已抄送邮箱 {}  - 抄送 bool   {}  修改 bool {}<<", trigger_type, SendEmail, bool, updHis);
                                }else{
                                    // 发送失败
                                    log.error(">>自动化  [RESend] - trigger_type [{}] 抄送失败!!!", trigger_type, SendEmail);

                                }
                                continue;
                            }

                        }
                        break;
                }
            } catch (Exception e) {
                log.error(">>>>>>>>>EmailRetry.RESend 错误 :{}", e.getMessage());
            }


        }else{
            log.info("邮件重试抄送》》》》暂无");
        }

    }

















    /**2022年10月28日16:13:42
     * 服务快到期发送
     * case:12
     */
    public void emailServiceOperation() {
        String Outcolumns[] = {"id", "企业名称", "邮箱", "企业Id", "快到期张数", "快到期最小时间", "快到期最大时间"};
        String keys[] = {"id", "dept_name", "email", "dept_id", "count", "record_date", "nextDay"};

        Map<String, Object> findMap = new HashMap<>();
        findMap.put("trigger_type", "12"); //自动化触发类型 服务快到期

        Map<String, Object> channel_idMap = new HashMap<>();

        List<String> channel_id = new ArrayList<String>();
        channel_id.add("IsNull");
        channel_idMap.put("channel_id", channel_id);

        Map<String, Object> CcMessage_Map = new HashMap<>();


        /*这里获取所有服务快到期的内容*/
        HashMap<String, Object> configMap = new HashMap<>();
        configMap.put("config_key", "card.expiringSoonCount");
        String delay = yzWxByProductAgentMapper.findConfig(configMap);// 快到期 天数
        Map<String, Object> Pmap_expiringSoonCount = new HashMap<>();
        String record_date = VeDate.getStringDate();
        Pmap_expiringSoonCount.put("timetype", "5");
        Pmap_expiringSoonCount.put("staTime", record_date);
        String nextDay = VeDate.getNextDay(record_date, delay);
        nextDay = nextDay + " 23:59:59";
        Pmap_expiringSoonCount.put("endTime", nextDay);
        List<Map> maps = yzCardDueSoonMapper.SelectCardDueSoon(Pmap_expiringSoonCount);
        /*类型转化*/
        HashMap<String, Object> h = new HashMap<>();
        ArrayList<Map<String, Object>> Q = new ArrayList<>();
        for (Map s : maps) {
            h = (HashMap<String, Object>) s;
            Q.add(h);
        }

        String create_by = " [平台] - " + " [自动化] ";
        String newName = UUID.randomUUID().toString().replace("-", "") + "_Duesoon";
        String task_name = "  [服务快到期] [" + record_date + " ~ " + nextDay + "]";
        String SaveUrl = "/getcsv/" + newName + ".csv";
        Map<String, Object> task_map = new HashMap<String, Object>();
        task_map.put("auth", create_by);
        task_map.put("task_name", task_name);
        task_map.put("url", SaveUrl);
        task_map.put("agent_id", "100");
        task_map.put("type", "41"); //对应 字典表的 执行日志类别
        yzExecutionTaskMapper.add(task_map);//添加执行 任务表
        Map<String, Object> defOutcolumns = new HashMap<>();
        defOutcolumns.put("record_date", record_date);
        defOutcolumns.put("nextDay", nextDay);

        writeCSV.OutCSVObj(Q, newName, Outcolumns, keys, defOutcolumns, 100);
        yzExecutionTaskMapper.set_end_time(task_map);//任务结束
        String taskId = "" + task_map.get("id");



        /*判断查询出来的服务快到期的集合是不是空或者null*/
        if (maps != null && maps.size() > 0) {
            /*说明有数据 查询运维邮箱那些*/
            List<Map<String, Object>> emailDept = yzAutomationCcMapper.findConcise(findMap);
            /*是否有地址或者是不是null*/
            if (emailDept != null && emailDept.size() > 0) {
                for (Map map : emailDept) {
                    //将map参数放入 cc_parameter

                    List emailDeptUrl = yzAutomationCcUrlMapper.findConcise(map);
                    if (emailDeptUrl != null && emailDeptUrl.size() > 0) {
                        String execution_template = map.get("execution_template").toString();
                        CcMessage_Map.put("count", maps.get(0).get("count"));
                        CcMessage_Map.put("taskId", taskId);
                        if (execution_template.equals("1")) {
                            for (Object eM : emailDeptUrl) {
                                if (eM != null && eM.toString().length() > 0) {

                                    Map sendEmail = (Map<String, Object>) eM;
                                    String email = sendEmail.get("email").toString();
                                    Map<String, Object> saveHisMap = new HashMap<>();
                                    saveHisMap.put("cc_id", map.get("id"));
                                    saveHisMap.put("cc_url", "");
                                    saveHisMap.put("cc_email", email);
                                    saveHisMap.put("cc_state", "1");//已抄送

//                                    /*测试map放入 count   ui task_id 能否在 重试发送邮件中存在*/

//                                    HashMap<String, Object> reNeed = new HashMap<>();
//                                    reNeed.put("count",Count);
//                                    reNeed.put("taskId",taskId);
//                                    String cc_parameter = JSON.toJSONString(reNeed);
                                    String cc_parameter = JSON.toJSONString(map);
                                    //String cc_parameter = JSON.toJSONString(CcMessage_Map);
                                    cc_parameter = cc_parameter.length() > 500 ? cc_parameter.substring(0, 500) : cc_parameter;
                                    saveHisMap.put("cc_parameter", cc_parameter);
                                    Map<String, Object> Rmap = null;
                                    Boolean bool = false;
                                    String remark = "", cc_result = "0";
                                    try {
                                        Rmap = emailCc.ServiceOperation(CcMessage_Map, email);
                                        bool = (Boolean) Rmap.get("bool");
                                        if (bool) {
                                            cc_result = "1";
                                            log.info("消费者:邮件发送完毕");
                                        }
                                    } catch (Exception e) {
                                        remark = e.getMessage();
                                        remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                                    }
                                    saveHisMap.put("remark", remark);
                                    saveHisMap.put("cc_result", cc_result);
                                    boolean saveHis = yzAutomationCcHisMapper.save(saveHisMap) > 0;
                                    log.info(">>自动化 [EmailPassageway] 已抄送邮箱{}  - 插入抄送记录 bool   {} <<", sendEmail, saveHis);
                                } else {
                                    log.error(">>自动化 邮件抄送给运维===>>>失败:邮箱未获取到");
                                }
                            }
                        } else {
                            log.error("[自动化:邮件抄送给运维]==>>失败:信息模板不批对");
                        }
                    }

                }
            }
        }

    }
    @Resource
    private YzCardMapper yzCardMapper;
    @Resource
    private MyDictionary myDictionary;

    /**2022年10月31日16:16:18
     * 有用量非正常状态
     * case 4
     */
    public void CCCardAbnormalStatus() {

        String Outcolumns[] = {"MSISDN","ICCID","IMSI","IMEI","所属通道","卡状态","状态描述","通道状态","同步时间","已使用用量(MB)","剩余用量(MB)","到期时间","备注","分组","激活日期","发货日期"};
        String keys[] = {"msisdn","iccid","imsi","imei","cd_name","status_ShowId_value","status_Id_value","cd_status_value","syn_Time","used","remaining","due_expire_time","remarks","customize_grouping","activate_date","deliver_date"};


        Map<String,Object> findMap = new HashMap<>();
        findMap.put("trigger_type","4");

        List<Map<String,Object>> out_list = new ArrayList<>();
        Map findStatusAbnormal_map = new HashMap();

        Map<String, Object> CcMessage_Map = new HashMap<>();
        String taskId = "";

        List<Map<String,Object>> cardList = yzCardMapper.findStatusAbnormal(findStatusAbnormal_map);//查询已订购用量状态异常卡号
        if(cardList!=null){
            String create_by = " [平台] - " + " [自动化] ";
            String newName = UUID.randomUUID().toString().replace("-", "") + "_AbnormalStatus";
            String task_name = "- 已订购用量状态已停机 抄送 [" + com.yunze.common.utils.yunze.VeDate.getStringDate() + "] ";
            String SaveUrl = "/getcsv/" + newName + ".csv";
            SaveUrl = "/getcsv/" + newName + ".csv";
            Map<String, Object> task_map = new HashMap<String, Object>();
            task_map.put("auth", create_by);
            task_map.put("task_name", task_name);
            task_map.put("url", SaveUrl);
            task_map.put("agent_id", "100");
            task_map.put("type", "14"); //对应 字典表的 执行日志类别
            yzExecutionTaskMapper.add(task_map);//添加执行 任务表

            for (int j = 0; j < cardList.size(); j++) {
                Map<String,Object> CarMap = new HashMap();
                CarMap.putAll(cardList.get(j));
                CarMap.put("status_Id_value",myDictionary.getdictLabel("yunze_card_status_type",CarMap.get("status_Id").toString()));
                CarMap.put("cd_status_value",myDictionary.getdictLabel("channel_status",CarMap.get("cd_status").toString()));
                out_list.add(CarMap);
            }
            writeCSV.Write(newName,out_list,Outcolumns,null,keys);
            yzExecutionTaskMapper.set_end_time(task_map);//任务结束
            taskId = ""+task_map.get("id");
            CcMessage_Map.put("taskId",taskId);
            CcMessage_Map.put("Count",""+out_list.size());

        }else {
            log.info("CCCardAbnormalStatus 已订购用量状态已停机未获取到 数据 抄送取消");
        }

        if(out_list.size()>0){
            List<Map<String, Object>> AutomationCcArr =  yzAutomationCcMapper.findConcise(findMap);//获取自动化 抄送 组
            if (AutomationCcArr != null && AutomationCcArr.size() > 0) {
                for (int i = 0; i < AutomationCcArr.size(); i++) {
                    Map<String, Object> CCObj = AutomationCcArr.get(i);
                    List<Map<String, Object>> AutomationCcUrlArr = yzAutomationCcUrlMapper.findConcise(CCObj);//获取自动化 抄送 邮箱

                    if (AutomationCcUrlArr != null && AutomationCcUrlArr.size() > 0) {
                        String execution_template = CCObj.get("execution_template").toString();
                        CCObj.put("taskId",taskId);
                        CCObj.put("Count",out_list.size());
                        if (execution_template.equals("1")) {
                            for (int j = 0; j < AutomationCcUrlArr.size(); j++) {
                                Object eM = AutomationCcUrlArr.get(j).get("email");
                                if (eM != null && eM.toString().length() > 0) {
                                    String SendEmail = eM.toString();
                                    Map<String, Object> saveHisMap = new HashMap<>();
                                    saveHisMap.put("cc_id", CCObj.get("id"));
                                    saveHisMap.put("cc_url", "");
                                    saveHisMap.put("cc_email", SendEmail);
                                    saveHisMap.put("cc_state", "1");//已抄送

                                    String cc_parameter = JSON.toJSONString(CCObj);
                                    cc_parameter = cc_parameter.length() > 500 ? cc_parameter.substring(0, 500) : cc_parameter;
                                    saveHisMap.put("cc_parameter", cc_parameter);
                                    Map<String, Object> Rmap = null;
                                    Boolean bool = false;
                                    String remark = "", cc_result = "0";
                                    try {
                                        Rmap = emailCc.CardStatusAbnormal_default(CcMessage_Map, SendEmail);
                                        bool = (Boolean) Rmap.get("bool");
                                        if (bool) {
                                            cc_result = "1";
                                        }
                                    } catch (Exception e) {
                                        remark = e.getMessage();
                                        remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                                    }
                                    saveHisMap.put("remark", remark);
                                    saveHisMap.put("cc_result", cc_result);
                                    boolean saveHis = yzAutomationCcHisMapper.save(saveHisMap) > 0;
                                    log.info(">>自动化 [CCCardAbnormalStatus] 已抄送邮箱{}  - 插入抄送记录 bool   {} <<", SendEmail, saveHis);
                                } else {
                                    log.error(">>自动化 [CCCardAbnormalStatus] 抄送邮箱未获取到  - 抄送取消  {} <<", eM);
                                }
                            }
                        } else {
                            log.error(">>自动化 [CCCardAbnormalStatus] 抄送模板不批对  - 抄送取消  {} <<");
                        }
                    } else {
                        log.error(">>自动化 [CCCardAbnormalStatus] 获取自动化 抄送 邮箱 未找到数据 - 抄送取消  {} <<");
                    }
                }
            }
        }
    }

    /**2022年11月14日10:48:32
     * 自动化 邮件抄送 [未划分资费组]
     * CASE:5
     */

    public void PayGroup() {
        Map<String, Object> findMap = new HashMap<>();
        findMap.put("trigger_type", "5"); //自动化触发类型 未划分资费组

        Map findStatusAbnormal_map = new HashMap();

        List<String> package_id = new ArrayList<>();
        package_id.add("IsNull");
        findStatusAbnormal_map.put("package_id", package_id); //资费组

        Map<String, Object> CcMessage_Map = new HashMap<>();

        Integer Count = yzCardMapper.selMapCount(findStatusAbnormal_map);//查询总数

        if (Count != null && Count > 0) {
            List<Map<String, Object>> AutomationCcArr = yzAutomationCcMapper.findConcise(findMap);//获取自动化 抄送 组
            if (AutomationCcArr != null && AutomationCcArr.size() >= 0) {
                for (int i = 0; i < AutomationCcArr.size(); i++) {
                    Map<String, Object> CCObj = AutomationCcArr.get(i);
                    List<Map<String, Object>> AutomationCcUrlArr = yzAutomationCcUrlMapper.findConcise(CCObj);//获取自动化 抄送 邮箱

                    if (AutomationCcUrlArr != null && AutomationCcUrlArr.size() > 0) {
                        String execution_template = CCObj.get("execution_template").toString();
                        CcMessage_Map.put("Count", Count);
                        CcMessage_Map.put("emailMap", findStatusAbnormal_map);

                        if (execution_template.equals("1")) {
                            for (int j = 0; j < AutomationCcUrlArr.size(); j++) {
                                Object eM = AutomationCcUrlArr.get(j).get("email");
                                if (eM != null && eM.toString().length() > 0) {
                                    String SendEmail = eM.toString();
                                    Map<String, Object> saveHisMap = new HashMap<>();
                                    saveHisMap.put("cc_id", CCObj.get("id"));
                                    saveHisMap.put("cc_url", "");
                                    saveHisMap.put("cc_email", SendEmail);
                                    saveHisMap.put("cc_state", "1");//已抄送

                                    String cc_parameter = JSON.toJSONString(CCObj);
                                    cc_parameter = cc_parameter.length() > 500 ? cc_parameter.substring(0, 500) : cc_parameter;
                                    saveHisMap.put("cc_parameter", cc_parameter);
                                    Map<String, Object> Rmap = null;
                                    Boolean bool = false;
                                    String remark = "", cc_result = "0";
                                    try {
                                        Rmap = emailCc.NotDividedIntoTariffGroups_default(CcMessage_Map, SendEmail);
                                        bool = (Boolean) Rmap.get("bool");
                                        if (bool) {
                                            cc_result = "1";
                                        }
                                    } catch (Exception e) {
                                        remark = e.getMessage();
                                        remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                                    }
                                    saveHisMap.put("remark", remark);
                                    saveHisMap.put("cc_result", cc_result);
                                    boolean saveHis = yzAutomationCcHisMapper.save(saveHisMap) > 0;
                                    log.info(">>自动化 [NoTariffGroup] 已抄送邮箱{}  - 插入抄送记录 bool   {} <<", SendEmail, saveHis);
                                } else {
                                    log.error(">>自动化 [NoTariffGroup] 抄送邮箱未获取到  - 抄送取消  {} <<", eM);
                                }
                            }
                        } else {
                            log.error(">>自动化 [NoTariffGroup] 抄送模板不批对  - 抄送取消  {} <<");
                        }
                    } else {
                        log.error(">>自动化 [NoTariffGroup] 获取自动化 抄送 邮箱 未找到数据 - 抄送取消  {} <<");
                    }
                }
            }
        }
    }


    /**2022年11月14日10:59:51
     * 自动化 邮件抄送 [未划分通道]
     * CASE:6
     */
    public void Passageway() {

        Map<String, Object> findMap = new HashMap<>();
        findMap.put("trigger_type", "6"); //自动化触发类型 未划分通道

        Map<String, Object> channel_idMap = new HashMap<>();

        List<String> channel_id = new ArrayList<String>();
        channel_id.add("IsNull");
        channel_idMap.put("channel_id", channel_id);

        Map<String, Object> CcMessage_Map = new HashMap<>();

        Integer Count = yzCardMapper.selMapCount(channel_idMap);//查询总数

        // System.out.println(Count);

        if (Count != null && Count > 0) {
            List<Map<String, Object>> AutomationCcArr = yzAutomationCcMapper.findConcise(findMap);//获取自动化 抄送 组
            if (AutomationCcArr != null && AutomationCcArr.size() > 0) {
                for (int i = 0; i < AutomationCcArr.size(); i++) {
                    Map<String, Object> CCObj = AutomationCcArr.get(i);
                    List<Map<String, Object>> AutomationCcUrlArr = yzAutomationCcUrlMapper.findConcise(CCObj);//获取自动化 抄送 邮箱

                    if (AutomationCcUrlArr != null && AutomationCcUrlArr.size() > 0) {
                        String execution_template = CCObj.get("execution_template").toString();
                        CcMessage_Map.put("Count", Count);
                        if (execution_template.equals("1")) {
                            for (int j = 0; j < AutomationCcUrlArr.size(); j++) {
                                Object eM = AutomationCcUrlArr.get(j).get("email");
                                if (eM != null && eM.toString().length() > 0) {
                                    String SendEmail = eM.toString();
                                    Map<String, Object> saveHisMap = new HashMap<>();
                                    saveHisMap.put("cc_id", CCObj.get("id"));
                                    saveHisMap.put("cc_url", "");
                                    saveHisMap.put("cc_email", SendEmail);
                                    saveHisMap.put("cc_state", "1");//已抄送


                                    Map<String, Object> CCMap = new HashMap<>();

                                    Map<String, Object> emailMap = new HashMap<>();

                                    List<String> channel_idArr = new ArrayList<>();
                                    channel_idArr.add("IsNull");
                                    emailMap.put("channel_id", channel_idArr);//new 一个map 把List<String>放入
                                    emailMap.put("Count", Count);//new 一个map 把String放入
                                    CCMap.put("Count",Count);
                                    CCMap.put("emailMap",emailMap);
                                    String cc_parameter = JSON.toJSONString(CCMap);
                                    cc_parameter = cc_parameter.length() > 500 ? cc_parameter.substring(0, 500) : cc_parameter;
                                    saveHisMap.put("cc_parameter", cc_parameter);
                                    Map<String, Object> Rmap = null;
                                    Boolean bool = false;
                                    String remark = "", cc_result = "0";
                                    try {

                                        Rmap = emailCc.UndividedChannel_default(CCMap, SendEmail);
                                        bool = (Boolean) Rmap.get("bool");
                                        if (bool) {
                                            cc_result = "1";
                                        }
                                    } catch (Exception e) {
                                        remark = e.getMessage();
                                        remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                                    }
                                    saveHisMap.put("remark", remark);
                                    saveHisMap.put("cc_result", cc_result);
                                    boolean saveHis = yzAutomationCcHisMapper.save(saveHisMap) > 0;
                                    log.info(">>自动化 [EmailPassageway] 已抄送邮箱{}  - 插入抄送记录 bool   {} <<", SendEmail, saveHis);
                                } else {
                                    log.error(">>自动化 [EmailPassageway] 抄送邮箱未获取到  - 抄送取消  {} <<", eM);
                                }
                            }
                        } else {
                            log.error(">>自动化 [EmailPassageway] 抄送模板不批对  - 抄送取消  {} <<");
                        }
                    } else {
                        log.error(">>自动化 [EmailPassageway] 获取自动化 抄送 邮箱 未找到数据 - 抄送取消  {} <<");
                    }
                }
            }
        }

    }



    /**2022年11月14日11:04:16
     *轮询-卡状态
     * case 7
     */
    public void CardConsumption() {
        Map<String, Object> findMap = new HashMap<>();
        findMap.put("trigger_type", "7"); //自动化触发类型 未划分资费组
        Map<String, Object> CcMessage_Map = new HashMap<>();

        Map<String, Object> findCardMap = new HashMap<>();
        List<String> agent_idArr = new ArrayList<>();
        agent_idArr.add("100");
        //findCardMap.put("agent_id",agent_idArr);//公司所属

        findCardMap.put("dimensionField", "1"); //
        findCardMap.put("dimensionType", "2"); //
        findCardMap.put("dimensionValue", "0.0"); //

        List<Map<String, Object>> AutomationCcArr = yzAutomationCcMapper.findConcise(findMap);//获取自动化 抄送 组
        if (AutomationCcArr != null && AutomationCcArr.size() > 0) {


            for (int i = 0; i < AutomationCcArr.size(); i++) {
                Map<String, Object> CCObj = AutomationCcArr.get(i);
                if (CCObj.get("dep_id") != null) {
                    String dep_id = CCObj.get("dep_id").toString();
                    if (!dep_id.equals("100")) {
                        agent_idArr.add(dep_id);
                    }
                }
                List<String> operationArr = new ArrayList<>();
                if (CCObj.get("operation_type") != null) {
                    String arr[] = CCObj.get("operation_type").toString().split(",");
                    for (int j = 0; j < arr.length; j++) {//java string数组 添加到list
                        String obj = arr[j];
                        if (obj.length() > 0) {
                            operationArr.add(obj);
                        }
                    }
                }

                List<String> channelArr = new ArrayList<>();
                if (CCObj.get("channel_id") != null) {
                    String lst[] = CCObj.get("channel_id").toString().split(",");
                    for (int j = 0; j < lst.length; j++) {//java string数组 添加到list
                        String obj = lst[j];
                        if (obj.length() > 0) {
                            channelArr.add(obj);
                        }
                    }
                }
                if (operationArr.size() > 0) {
                    findCardMap.put("operation_type", operationArr);
                    findCardMap.put("cd_operator_type", operationArr);
                }
                if (channelArr.size() > 0) {
                    findCardMap.put("channel_id", channelArr);
                    findCardMap.put("cArr", channelArr);
                }
                findCardMap.put("agent_id", agent_idArr);

                //删除 发送用不到的 key 赋值 前端 选中树控件key
                findCardMap.remove("operation_type");
                //findCardMap.remove("agent_id");

                findCardMap.put("trreAgent_id", agent_idArr);


                Integer Count = yzCardMapper.selMapCount(findCardMap);//查询总数

                if (Count != null && Count > 0) {
                    List<Map<String, Object>> AutomationCcUrlArr = yzAutomationCcUrlMapper.findConcise(CCObj);//获取自动化 抄送 邮箱
                    if (AutomationCcUrlArr != null && AutomationCcUrlArr.size() > 0) {
                        String execution_template = CCObj.get("execution_template").toString();

                        CcMessage_Map.put("Count", Count);
                        if (execution_template.equals("1")) {
                            for (int j = 0; j < AutomationCcUrlArr.size(); j++) {
                                Object eM = AutomationCcUrlArr.get(j).get("email");
                                if (eM != null && eM.toString().length() > 0) {
                                    String SendEmail = eM.toString();
                                    Map<String, Object> saveHisMap = new HashMap<>();
                                    saveHisMap.put("cc_id", CCObj.get("id"));
                                    saveHisMap.put("cc_url", "");
                                    saveHisMap.put("cc_email", SendEmail);
                                    saveHisMap.put("cc_state", "1");//已抄送

                                    String cc_parameter = JSON.toJSONString(CCObj);
                                    cc_parameter = cc_parameter.length() > 500 ? cc_parameter.substring(0, 500) : cc_parameter;
                                    saveHisMap.put("cc_parameter", cc_parameter);
                                    Map<String, Object> Rmap = null;
                                    Boolean bool = false;
                                    String remark = "", cc_result = "0";
                                    try {
                                        CcMessage_Map.put("findCardMap", findCardMap);
                                        Rmap = emailCc.CardConsumption_default(CcMessage_Map, SendEmail);
                                        bool = (Boolean) Rmap.get("bool");
                                        if (bool) {
                                            cc_result = "1";
                                        }
                                    } catch (Exception e) {
                                        remark = e.getMessage();
                                        remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                                    }
                                    saveHisMap.put("remark", remark);
                                    saveHisMap.put("cc_result", cc_result);
                                    boolean saveHis = yzAutomationCcHisMapper.save(saveHisMap) > 0;
                                    log.info(">>自动化 [CardConsumption] 已抄送邮箱{}  - 插入抄送记录 bool   {} <<", SendEmail, saveHis);
                                } else {
                                    log.error(">>自动化 [CardConsumption] 抄送邮箱未获取到  - 抄送取消  {} <<", eM);
                                }
                            }
                        } else {
                            log.error(">>自动化 [CardConsumption] 抄送模板不批对  - 抄送取消  {} <<");
                        }
                    } else {
                        log.error(">>自动化 [CardConsumption] 获取自动化 抄送 邮箱 未找到数据 - 抄送取消  {} <<");
                    }


                }
            }
        }


    }

    /**自动化任务邮件抄送超百分比（80）
     * 2022年10月28日16:27:49
     * @param msg
     * CASE:8
     */

    @Resource
    private YzCardUsageReminderMapper yzCardUsageReminderMapper;

    public void Reminder(String msg) {

        String Outcolumns[] = {"iccid", "资费id", "资费激活名称", "APN 名称", "总量(MB)", "使用量(MB)", "剩余量(MB)", "已用百分比(%)", "创建时间"};
        String keys[] = {"iccid", "offeringId", "offeringName", "apnName", "totalAmount", "useAmount", "remainAmount", "percentage", "create_date"};
        int OutSize = 50;//每 50条数据输出一次

        if (StringUtils.isEmpty(msg)) {
            return;
        }
//        Map<String,Object> Pmap = JSON.parseObject(msg);
//        Integer parameter = Integer.parseInt(Pmap.get("parameter").toString()) ;

        Integer parameter = Integer.parseInt(msg) ;  //80

        Map<String, Object> findMap = new HashMap<>();
        findMap.put("trigger_type", "8"); //自动化触发类型 未划分资费组

        List<Map<String,Object>> out_list = new ArrayList<>();
        Map<String, Object> CcMessage_Map = new HashMap<>();
        String taskId = "";

        Map<String, Object> map = new HashMap<>();
        map.put("dimensionField","4");
        map.put("dimensionType","1");
        map.put("percentage",parameter);
        List<Map<String, Object>> list = yzCardUsageReminderMapper.mailId(map);

        if(list != null){
            String create_by = " [平台] - " + " [自动化] ";
            String newName = UUID.randomUUID().toString().replace("-", "") + "_Reminder";
            String task_name = " 上游套餐超过百分比 抄送 [" + com.yunze.common.utils.yunze.VeDate.getStringDate() + "] ";
            String SaveUrl = "/getcsv/" + newName + ".csv";
            SaveUrl = "/getcsv/" + newName + ".csv";
            Map<String, Object> task_map = new HashMap<String, Object>();
            task_map.put("auth", create_by);
            task_map.put("task_name", task_name);
            task_map.put("url", SaveUrl);
            task_map.put("agent_id", "100");
            task_map.put("type", "32"); //对应 字典表的 执行日志类别
            yzExecutionTaskMapper.add(task_map);//添加执行 任务表

            for (int j = 0; j < list.size(); j++) {
                Map<String,Object> CarMap = new HashMap<>();
                CarMap.putAll(list.get(j));
                out_list.add(CarMap);
            }
            writeCSV.OutCSVObj(out_list, newName,Outcolumns, keys,null,OutSize);
            yzExecutionTaskMapper.set_end_time(task_map);//任务结束
            taskId = ""+task_map.get("id");
            CcMessage_Map.put("taskId",taskId);// 获取 执行任务表的ID
            CcMessage_Map.put("Count",""+out_list.size());
        }else {
            log.info("usageMailReminder 自动化任务邮件抄送【上游套餐超过百分比】未获取到 数据 抄送取消");
        }

        List<Map<String, Object>> AutomationCcArr = yzAutomationCcMapper.findConcise(findMap);//获取自动化 抄送 组
        if (AutomationCcArr != null && AutomationCcArr.size() > 0) {
            for (int i = 0; i < AutomationCcArr.size(); i++) {
                Map<String, Object> CCObj = AutomationCcArr.get(i);
                List<Map<String, Object>> AutomationCcUrlArr = yzAutomationCcUrlMapper.findConcise(CCObj);//获取自动化 抄送 邮箱

                if (AutomationCcUrlArr != null && AutomationCcUrlArr.size() > 0) {
                    String execution_template = CCObj.get("execution_template").toString();
                    CCObj.put("taskId",taskId);
                    CCObj.put("Count",out_list.size());
                    if (execution_template.equals("1")) {
                        for (int j = 0; j < AutomationCcUrlArr.size(); j++) {
                            Object eM = AutomationCcUrlArr.get(j).get("email");
                            if (eM != null && eM.toString().length() > 0) {
                                String SendEmail = eM.toString();
                                Map<String, Object> saveHisMap = new HashMap<>();
                                saveHisMap.put("cc_id", CCObj.get("id"));
                                saveHisMap.put("cc_url", "");
                                saveHisMap.put("cc_email", SendEmail);
                                saveHisMap.put("cc_state", "1");//已抄送

                                String cc_parameter = JSON.toJSONString(CCObj);
                                cc_parameter = cc_parameter.length() > 500 ? cc_parameter.substring(0, 500) : cc_parameter;
                                saveHisMap.put("cc_parameter", cc_parameter);
                                Map<String, Object> Rmap = null;
                                Boolean bool = false;
                                String remark = "", cc_result = "0";
                                try {

                                    Rmap = emailCc.usageMailReminder_default(CcMessage_Map, SendEmail);
                                    bool = (Boolean) Rmap.get("bool");
                                    if (bool) {
                                        cc_result = "1";
                                    }

                                } catch (Exception e) {
                                    remark = e.getMessage();
                                    remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                                }
                                saveHisMap.put("remark", remark);
                                saveHisMap.put("cc_result", cc_result);
                                boolean saveHis = yzAutomationCcHisMapper.save(saveHisMap) > 0;
                                log.info(">>自动化 [usageMailReminder] 已抄送邮箱{}  - 插入抄送记录 bool   {} <<", SendEmail, saveHis);
                            } else {
                                log.error(">>自动化 [usageMailReminder] 抄送邮箱未获取到  - 抄送取消  {} <<", eM);
                            }
                        }
                    } else {
                        log.error(">>自动化 [usageMailReminder] 抄送模板不批对  - 抄送取消  {} <<");
                    }
                } else {
                    log.error(">>自动化 [usageMailReminder] 获取自动化 抄送 邮箱 未找到数据 - 抄送取消  {} <<");
                }
            }
        }
    }


    /**2022年10月31日16:21:24
     *API同步错误-运营类型
     * case 9
     */
    @Resource
    private YzCardPollingErrorGroupMapper yzCardPollingErrorGroupMapper;

    @Resource
    private YzCardPollingErrorMapper yzCardPollingErrorMapper;

    public void Aseot(String trigger_type) {


        String Outcolumns[] = {"id","错误代码","错误信息","通道编码","创建时间","最近一次修改时间","是否需要通知","卡总数"};
        String keys[] = {"id","codeOn","message","cd_code","create_date","upd_date","is_notice","ct_sum"};


        String Outcolumns_1[] = {"id","iccid","错误代码","错误信息","通道编码","cd_id","通道名称","通道别称","登录账号","创建时间","最近一次修改时间","是否需要通知","返回数据"};
        String keys_1[] = {"id","iccid","codeOn","message","cd_code","cd_id","cd_name","cd_alias","cd_useraccount","create_date","upd_date","is_notice","rt_map"};


        String Outcolumns_2[] = {"cd_id","通道名称","通道别称","登录账号"};
        String keys_2[] = {"cd_id","cd_name","cd_alias","cd_useraccount"};

        int OutSize = 50;//每 50条数据输出一次



        Map<String, Object> findMap = new HashMap<>();
        findMap.put("trigger_type", trigger_type); // 自动化触发类型 ： 9  API同步错误-运营类型 | 10  API同步错误-非运营类型
        Map<String, Object> findErrorMap = new HashMap<>();
        String type = "";
        if(trigger_type.equals("9")){
            type = "运营类型";
            findErrorMap.put("notIn",0);
        }else if (trigger_type.equals("10")){
            type = "非运营类型";
            findErrorMap.put("notIn",1);
        }




        Map findStatusAbnormal_map = new HashMap();

        Map<String, Object> CcMessage_Map = new HashMap<>();


        findErrorMap.put("is_notice","1");
        findErrorMap.put("isToDay","1");

        Map<String,Object> findDictData_map = new HashMap();
        findDictData_map.put("dictType","api_businessError_code");

        List<Map<String,Object>> errorCode = yzCardMapper.selectDictDataByType(findDictData_map);//获取 ‘上游业务错误编码’

        Map<String, Object> codeOnMap = new HashMap<>();
        List<Map <String,Object>> errorList = new ArrayList<>();
        List<String> exTypeArr = new ArrayList<>();
        if(errorCode!=null && errorCode.size()>0){
            for (int i = 0; i < errorCode.size(); i++) {
                Map<String,Object> codeObj = errorCode.get(i);
                String dict_label = codeObj.get("dict_label").toString();
                String dict_value = codeObj.get("dict_value").toString();
                List<String> exDictValueArr = new ArrayList<>();
                if(inIt(exTypeArr,dict_label)){
                    exDictValueArr = (List<String>)codeOnMap.get(dict_label);
                }
                exDictValueArr.add(dict_value);
                codeOnMap.put(dict_label,exDictValueArr);
            }

            //循环 去查询 某个通道类型下 业务错误编码【通知运营去处理的错误问题 如 ：‘卡号不属于本企业’】
            for(String key:codeOnMap.keySet()){
                List<String> cdCodeArr = new ArrayList<>();
                cdCodeArr.add(key);
                if(key.equals("YiDong_EC")){
                    cdCodeArr.add("YiDong_EC_Combo");//同属于 移动ECv5 用来区分查询用量的时候是查询当月还是当前使用账期用量
                }else if(key.equals("YiDong_ECv2")){
                    cdCodeArr.add("YiDong_ECv2_Combo");//同属于 移动ECv2 用来区分查询用量的时候是查询当月还是当前使用账期用量
                }
                findErrorMap.put("cdCodeArr",cdCodeArr);
                findErrorMap.put("codeOnArr",codeOnMap.get(key));
                System.out.println(JSON.toJSONString(findErrorMap));
                List<Map <String,Object>> errorList_child = yzCardPollingErrorGroupMapper.findErrorList(findErrorMap);
                if(errorList_child!=null && errorList_child.size()>0){
                    errorList.addAll(errorList_child);
                }
            }
        }else{
            errorList =  yzCardPollingErrorGroupMapper.findErrorList(findErrorMap);
        }
        Integer Count = errorList!=null?errorList.size():0;
        if (Count > 0) {

            List<Map<String, Object>> AutomationCcArr = yzAutomationCcMapper.findConcise(findMap);//获取自动化 抄送 组
            if (AutomationCcArr != null && AutomationCcArr.size() > 0) {
                String taskId = "";



                String create_by = " [平台] - " + " [自动化] ";
                String newName = UUID.randomUUID().toString().replace("-", "") + "_ErrorGroupApi";
                String newName_1 = UUID.randomUUID().toString().replace("-", "") + "_ApiError";
                String newName_2 = UUID.randomUUID().toString().replace("-", "") + "_ApiRout";
                String task_name = " IoTLink 上游数据同步错误  [" + type + "] [" + com.yunze.common.utils.yunze.VeDate.getStringDate() + "]";
                String SaveUrl = "/getcsv/" + newName + ".csv,"+"/getcsv/" + newName_1 + ".csv,"+"/getcsv/" + newName_2 + ".csv";
                Map<String, Object> task_map = new HashMap<String, Object>();
                task_map.put("auth", create_by);
                task_map.put("task_name", task_name);
                task_map.put("url", SaveUrl);
                task_map.put("agent_id", "100");
                task_map.put("type", "32"); //对应 字典表的 执行日志类别
                yzExecutionTaskMapper.add(task_map);//添加执行 任务表


                writeCSV.OutCSVObj(errorList, newName,Outcolumns, keys,null,OutSize);
                yzExecutionTaskMapper.set_end_time(task_map);//任务结束
                taskId = ""+task_map.get("id");

                int errorCardCount = 0;
                for (int i = 0; i < errorList.size(); i++) {
                    Map <String,Object> eMap = errorList.get(i);
                    Integer ct_sum = eMap.get("ct_sum")!=null?Integer.parseInt(eMap.get("ct_sum").toString()):0;
                    errorCardCount += ct_sum;
                }

                Integer rCount = 0;

                writeCSV.OutCSVObj(errorList, newName,Outcolumns, keys,null,OutSize);

                List<Map <String,Object>> errorDsList =  yzCardPollingErrorMapper.selMapRelevance(findErrorMap);
                if(errorDsList!=null && errorDsList.size()>0){
                    writeCSV.OutCSVObj(errorDsList, newName_1,Outcolumns_1, keys_1,null,OutSize);
                    findErrorMap.put("isGroupBy",1);
                    List<Map <String,Object>> errorisGroupBy =  yzCardPollingErrorMapper.selMapRelevance(findErrorMap);
                    if(errorisGroupBy!=null && errorisGroupBy.size()>0) {
                        rCount = errorisGroupBy.size();
                        writeCSV.OutCSVObj(errorisGroupBy, newName_2, Outcolumns_2, keys_2, null, OutSize);
                    }
                }

                CcMessage_Map.put("taskId",taskId);// 获取 执行任务表的ID
                CcMessage_Map.put("describe","IoTLink API同步错误 [ "+type+" ] 错误类型 [ "+errorList.size()+" ] 个，涉及卡号 [ "+errorCardCount+" ] 个！，涉及通道 [ "+rCount+" ] 个！");
                CcMessage_Map.put("heartext"," IoTLink API同步错误 ["+type+"]业务需要您及时处理！，涉及卡号 [ "+errorCardCount+" ] 个！，涉及通道 [ "+rCount+" ] 个！");



                for (int i = 0; i < AutomationCcArr.size(); i++) {
                    Map<String, Object> CCObj = AutomationCcArr.get(i);
                    List<Map<String, Object>> AutomationCcUrlArr = yzAutomationCcUrlMapper.findConcise(CCObj);//获取自动化 抄送 邮箱

                    if (AutomationCcUrlArr != null && AutomationCcUrlArr.size() > 0) {
                        String execution_template = CCObj.get("execution_template").toString();
                        CcMessage_Map.put("emailMap", findStatusAbnormal_map);

                        if (execution_template.equals("1")) {
                            for (int j = 0; j < AutomationCcUrlArr.size(); j++) {
                                Object eM = AutomationCcUrlArr.get(j).get("email");
                                if (eM != null && eM.toString().length() > 0) {
                                    String SendEmail = eM.toString();
                                    Map<String, Object> saveHisMap = new HashMap<>();
                                    saveHisMap.put("cc_id", CCObj.get("id"));
                                    saveHisMap.put("cc_url", "");
                                    saveHisMap.put("cc_email", SendEmail);
                                    saveHisMap.put("cc_state", "1");//已抄送

                                    saveHisMap.put("cc_parameter", JSON.toJSONString(CcMessage_Map));
                                    Map<String, Object> Rmap = null;
                                    Boolean bool = false;
                                    String remark = "", cc_result = "0";
                                    try {
                                        Rmap = emailCc.CardApiSynError_default(CcMessage_Map, SendEmail);
                                        bool = (Boolean) Rmap.get("bool");
                                        if (bool) {
                                            cc_result = "1";
                                        }
                                    } catch (Exception e) {
                                        remark = e.getMessage();
                                        remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                                    }
                                    saveHisMap.put("remark", remark);
                                    saveHisMap.put("cc_result", cc_result);
                                    boolean saveHis = yzAutomationCcHisMapper.save(saveHisMap) > 0;
                                    log.info(">>自动化 [NoTariffGroup] 已抄送邮箱{}  - 插入抄送记录 bool   {} <<", SendEmail, saveHis);
                                } else {
                                    log.error(">>自动化 [NoTariffGroup] 抄送邮箱未获取到  - 抄送取消  {} <<", eM);
                                }
                            }
                        } else {
                            log.error(">>自动化 [NoTariffGroup] 抄送模板不批对  - 抄送取消  {} <<");
                        }
                    } else {
                        log.error(">>自动化 [NoTariffGroup] 获取自动化 抄送 邮箱 未找到数据 - 抄送取消  {} <<");
                    }
                }
            }
        }
    }


    /**2022年10月31日16:30:54
     * 续费通知
     * case 11
     */
    @Resource
    private YzApplicationforRenewalPrimaryMapper yzApplicationforRenewalPrimaryMapper;

    public void CCExecution() {

        Map<String, Object> findMap = new HashMap<>();
        findMap.put("trigger_type", "11"); //自动化触发类型 续费通知

        List<Map<String, Object>> sendInfoList = yzApplicationforRenewalPrimaryMapper.findEmailCC(null);

        List<Map<String, Object>> AutomationCcArr = yzAutomationCcMapper.findConcise(findMap);//获取自动化 抄送 组
        if (sendInfoList != null && sendInfoList.size() > 0 &&  AutomationCcArr != null && AutomationCcArr.size() > 0) {

            for (int k = 0; k < sendInfoList.size(); k++) {//抄送需要抄送的续费申请数组
                Map<String, Object> sendInfo = sendInfoList.get(k);

                Map<String, Object> CcMessage_Map = new HashMap<>();
                Map<String, Object> parMap = new HashMap<>();
                parMap.put("id",sendInfo.get("id"));

                CcMessage_Map.put("parMap",parMap);
                CcMessage_Map.put("card_sumCount",sendInfo.get("card_sumCount"));
                CcMessage_Map.put("amount",sendInfo.get("amount"));
                CcMessage_Map.put("info",sendInfo.get("info"));
                CcMessage_Map.put("create_time",sendInfo.get("create_time"));
                CcMessage_Map.put("dept_name",sendInfo.get("dept_name"));
                CcMessage_Map.put("title","点击查看详情");


                for (int i = 0; i < AutomationCcArr.size(); i++) {//抄送认循环
                    Map<String, Object> CCObj = AutomationCcArr.get(i);
                    List<Map<String, Object>> AutomationCcUrlArr = yzAutomationCcUrlMapper.findConcise(CCObj);//获取自动化 抄送 邮箱

                    if (AutomationCcUrlArr != null && AutomationCcUrlArr.size() > 0) {
                        String execution_template = CCObj.get("execution_template").toString();

                        if (execution_template.equals("1")) {
                            for (int j = 0; j < AutomationCcUrlArr.size(); j++) {

                                Object eM = AutomationCcUrlArr.get(j).get("email");
                                if (eM != null && eM.toString().length() > 0) {
                                    String SendEmail = eM.toString();
                                    Map<String, Object> saveHisMap = new HashMap<>();
                                    saveHisMap.put("cc_id", CCObj.get("id"));
                                    saveHisMap.put("cc_url", "");
                                    saveHisMap.put("cc_email", SendEmail);
                                    saveHisMap.put("cc_state", "1");//已抄送

                                    String cc_parameter = JSON.toJSONString(CcMessage_Map);
                                    cc_parameter = cc_parameter.length() > 500 ? cc_parameter.substring(0, 500) : cc_parameter;
                                    saveHisMap.put("cc_parameter", cc_parameter);
                                    Map<String, Object> Rmap = null;
                                    Boolean bool = false;
                                    String remark = "", cc_result = "0";
                                    try {
                                        Rmap = emailCc.ApplicationForRenewal_default(CcMessage_Map, SendEmail);
                                        bool = (Boolean) Rmap.get("bool");
                                        if (bool) {
                                            cc_result = "1";
                                        }
                                    } catch (Exception e) {
                                        remark = e.getMessage();
                                        remark = remark.length() > 240 ? remark.substring(0, 240) : remark;
                                    }
                                    saveHisMap.put("remark", remark);
                                    saveHisMap.put("cc_result", cc_result);
                                    boolean saveHis = yzAutomationCcHisMapper.save(saveHisMap) > 0;
                                    log.info(">>自动化 [EmailCCRenewal] 已抄送邮箱{}  - 插入抄送记录 bool   {} <<", SendEmail, saveHis);
                                } else {
                                    log.error(">>自动化 [EmailCCRenewal] 抄送邮箱未获取到  - 抄送取消  {} <<", eM);
                                }
                            }
                        } else {
                            log.error(">>自动化 [EmailCCRenewal] 抄送模板不批对  - 抄送取消  {} <<");
                        }
                    } else {
                        log.error(">>自动化 [EmailCCRenewal] 获取自动化 抄送 邮箱 未找到数据 - 抄送取消  {} <<");
                    }
                }

            }


        }
    }

    /**2022年10月31日16:33:12
     *同步上游卡号新增
     * case 13
     */

    @Resource
    private YzCardRouteMapper yzCardRouteMapper;

    @Resource
    private YzSynCardInfoMapper yzSynCardInfoMapper;

    public void SynUpstreamCardNumberAdd() {
        //1.状态 正常 且开启了需要同步上游成员 时
        Map<String, Object> findRouteID_Map = new HashMap<>();
        findRouteID_Map.put("FindCd_id", null);
        /*findRouteID_Map.put("cd_lunxun","notChoose");//是否轮训 不选择（只要是状态正常就去获取）*/
        findRouteID_Map.put("sync_upstream", "1");// 同步上游卡号数据

        Map<String, Object> User = new HashMap<>();
        Map<String, Object> dept = new HashMap<>();
        dept.put("deptName", "系统自动同步");
        dept.put("deptId", "100");
        User.put("dept", dept);


        List<Map<String, Object>> channelArr = yzCardRouteMapper.findRouteID(findRouteID_Map);
        if (channelArr != null && channelArr.size() > 0) {
            for (int i = 0; i < channelArr.size(); i++) {
                Map<String, Object> ChannelObj = channelArr.get(i);
                String channel_id = ChannelObj.get("cd_id").toString();
                String cd_name = ChannelObj.get("cd_name").toString();


                ChannelObj.put("channel_id", channel_id);
                ChannelObj.put("is_new", "1");//是否 需要新增到 card_info 表 【是】
                User.put("userName", "通道[" + channel_id + "]");
                String sync_data_type = ChannelObj.get("sync_data_type") != null ? ChannelObj.get("sync_data_type").toString() : null;//'上游返回的数据-同步类型'
                //String upstream_card_count = ChannelObj.get("upstream_card_count")!=null ?ChannelObj.get("upstream_card_count").toString():"0";//'上游成员卡总数'
                String sync_field_arr[] = ChannelObj.get("sync_field") != null ? ChannelObj.get("sync_field").toString().split(",") : null;//'自动同步的字段 如 activate_date,open_date'
                String sync_change_notification = ChannelObj.get("sync_change_notification") != null ? ChannelObj.get("sync_change_notification").toString() : null;//'上游成员变更是是否通知



                List<Map<String, Object>> recentSyncArr = yzSynCardInfoMapper.getSyncCardInfo(ChannelObj);// 获取标记了 需要新增的卡号
                if (recentSyncArr != null && recentSyncArr.size() > 0) {
                    List<Map<String, Object>> addArr = new ArrayList<>();//准备新增的数组
                    boolean imsi_bool = false, activate_date_bool = false, open_date_bool = false, remark_bool = false;//判断那些需要 修改或新增的字段
                    if (sync_field_arr != null) {
                        for (int j = 0; j < sync_field_arr.length; j++) {
                            String str_toLowerCase = sync_field_arr[j] != null ? sync_field_arr[j].toLowerCase() : "";
                            switch (str_toLowerCase) {
                                case "imsi":
                                    imsi_bool = true;
                                    break;
                                case "activate_date":
                                    activate_date_bool = true;
                                    break;
                                case "open_date":
                                    open_date_bool = true;
                                    break;
                                case "remark":
                                    remark_bool = true;
                                    break;
                            }
                        }
                    }
                    for (int j = 0; j < recentSyncArr.size(); j++) {
                        Map<String, Object> recentSync_Map = recentSyncArr.get(j);

                        String msisdn = recentSync_Map.get("msisdn") != null ? recentSync_Map.get("msisdn").toString() : null;
                        String iccid = recentSync_Map.get("iccid") != null ? recentSync_Map.get("iccid").toString() : null;
                        String imsi = recentSync_Map.get("imsi") != null ? recentSync_Map.get("imsi").toString() : null;
                        String activate_date = recentSync_Map.get("activate_date") != null ? recentSync_Map.get("activate_date").toString() : null;
                        String open_date = recentSync_Map.get("open_date") != null ? recentSync_Map.get("open_date").toString() : null;
                        String remark = recentSync_Map.get("remark") != null ? recentSync_Map.get("remark").toString() : null;
                        if (msisdn != null && iccid != null) {
                            //默认同步字段 msisdn，iccid channel_id 且不能为空
                            Map<String, Object> add_Map = new HashMap<>();
                            add_Map.put("msisdn", msisdn);
                            add_Map.put("iccid", iccid);
                            add_Map.put("channel_id", channel_id);
                            if (imsi_bool) {
                                add_Map.put("imsi", imsi);
                            }
                            if (activate_date_bool) {
                                add_Map.put("activate_date", activate_date);
                            }
                            if (open_date_bool) {
                                add_Map.put("open_date", open_date);
                            }
                            if (remark_bool) {
                                add_Map.put("remark", remark);
                            }
                            addArr.add(add_Map);
                        }
                    }
                    if (addArr != null && addArr.size() > 0) {
                        //模仿生成 批量上传的文件 生成 svc 再转换成 excle,将 新增指令 发送到 新增消费者去执行 【统一新增入口】
                        try {
                            String newName = UUID.randomUUID().toString().replace("-", "") + "_CardImport";
                            String keys[] = {"msisdn", "iccid", "imsi", "open_date", "activate_date", "agent_id", "channel_id", "is_pool", "batch_date", "remarks", "status_id", "package_id", "imei", "type", "network_type", "is_sms", "sms_number", "gprs", "user_id", "test_period_last_time", "silent_period_last_time"};
                            writeCSV.Write(newName, addArr, keys, null, keys, "/upload/uploadCard", true);
                            String flieUrlRx = "/upload/uploadCard/";
                            writeCSV.CsvOrExcle(flieUrlRx+newName, null, false,true);
                            uploadCard(User, newName+".xls",sync_change_notification,cd_name,addArr.size());
                            //修改 该批次卡的 需要新增状态 改为 0
                            Map<String,Object> upd_Map = new HashMap<>();
                            upd_Map.put("is_new","0");
                            upd_Map.put("updArr",addArr);
                            int upd_count = yzSynCardInfoMapper.updateArr(upd_Map);
                            log.info(" ==== {} [is_new = 0 ] 卡数量 {} 成功数量 {}", JSON.toJSONString(ChannelObj),addArr.size(),upd_count);
                        } catch (Exception e) {
                            log.error("模仿生成 批量上传的文件 CsvOrExcle 异常 {}",e.getMessage());
                        }

                    }
                }
            }
        }
    }


    /**
     * 工具方法
     * @param arr
     * @param eStr
     * @return
     */
    public boolean inIt(List<String> arr, String eStr){
        boolean bool = false;
        for (int i = 0; i < arr.size(); i++) {
            String str = arr.get(i);
            if(str.equals(eStr)){
                bool = true;
                break;
            }
        }
        return bool;
    }

    @Resource
    private RabbitTemplate rabbitTemplate;

    public String uploadCard(Map<String, Object> User, String ReadName,String sync_change_notification,String cd_name,int size) {
        String newName = UUID.randomUUID().toString().replace("-", "") + "_CardImport";
        try {
            /**
             * 获取当前项目的工作路径
             */
            File file2 = new File("");
            String filePath = file2.getCanonicalPath();
            String flieUrlRx = "/upload/uploadCard/";
            ReadName = flieUrlRx + ReadName;
            //1.创建路由 绑定 生产队列 发送消息
            //导卡 路由队列
            String polling_queueName = "admin_saveCard_queue";
            String polling_routingKey = "admin.saveCard.queue";
            String polling_exchangeName = "admin_exchange";//路由
            try {

                Map<String, Object> task_map = new HashMap<String, Object>();
                Map<String, String> Dept = (Map<String, String>)User.get("dept");
                String SaveUrl = "/getcsv/"+newName+".csv";
                String task_name ="物联卡管理 [自动导入] ";
                String  create_by = " [ "+Dept.get("deptName")+" ] - "+" [ "+User.get("userName")+" ] ";
                task_map.put("auth",create_by);
                task_map.put("task_name",task_name);
                task_map.put("url",SaveUrl);
                task_map.put("agent_id", Dept.get("deptId"));
                task_map.put("type","3");

                Map<String, Object> start_type = new HashMap<>();
                start_type.put("type", "importCardData");//启动类型
                start_type.put("filePath", filePath);//项目根目录
                start_type.put("ReadName", ReadName);//上传新文件名
                start_type.put("newName", newName);//输出文件名
                start_type.put("User", User);//登录用户信息
                start_type.put("pTaskMap", task_map);//
                yzExecutionTaskMapper.add(task_map);//添加执行 任务表

                rabbitTemplate.convertAndSend(polling_exchangeName, polling_routingKey, JSON.toJSONString(start_type), message -> {
                    // 设置消息过期时间 30 分钟 过期
                    message.getMessageProperties().setExpiration("" + (30 * 1000 * 60));
                    return message;
                });

                //判断通道信息变更时是否需要通知 需要通知时进行 通知
                if(sync_change_notification!=null && sync_change_notification.equals("1")){
                    try {
                        Map<String, Object> send_type = new HashMap<>();

                        Map<String, Object> CcMessage_Map = new HashMap<>();
                        CcMessage_Map.put("taskId",task_map.get("id"));// 获取 执行任务表的ID
                        CcMessage_Map.put("describe"," 卡号自动新增 ["+cd_name+"] | ["+size+"] 张卡号 ");
                        CcMessage_Map.put("heartext"," 卡号自动新增 ["+cd_name+"] | ["+size+"] 张卡号 ");
                        send_type.put("CcMessage_Map",CcMessage_Map);
                        send_type.put("trigger_type","13");
                        rabbitTemplate.convertAndSend("admin_exchange", "admin.EmaiSynCardInfo.queue", JSON.toJSONString(send_type), message -> {
                            // 设置消息过期时间 30 分钟 过期
                            message.getMessageProperties().setExpiration("" + (30 * 1000 * 60));
                            return message;
                        });
                    } catch (Exception e) {
                        log.error("通道变更邮件抄送异常 {}", e.getMessage());
                    }
                }
            } catch (Exception e) {
                log.error("导入 卡号 失败 {}" , e.getMessage());
                return ("物联卡管理 导入 操作失败！");
            }
        } catch (Exception e) {
            log.error(e.getMessage());
            return "上传excel异常";
        }
        return "导入指令 已发送 ! ";
    }
}
